package com.plm.mr.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * KEYIN 输入key:LongWritable
 * VALUEIN 输入value:Text
 * KEYOUT 输出key:Text
 * VALUEOUT 输出value:IntWritable
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private Text k = new Text();
    private IntWritable v = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 1获取一行
        // aa aa
        String line = value.toString();

        // 2切割
        String[] words = line.split(" ");

        // 3输出
        for (String word : words) {
            k.set(word);
            context.write(k, v);
        }
    }
}
